Ray Trace software package, release 2.0.2β (beta).
Author: Sam Buss
Univ. of California, San Diego
NEWLY REVISED: The latest beta version is at release 2.0.2, and was posted on the web on March 18, 2004. Release 2.0.2 has incorporated several bug fixes. The comment lines at the front of the source files RayTrace.cpp and RayTrace2.cpp show which version you have.
This software package accompanies my book 3D Computer Graphics: A Mathematical Introduction with OpenGL (Cambridge University Press, 2003). It implements a ray tracing package in C++ in an extensible, object-oriented fashion.
Overview: This ray tracing software is written an C++. It
contains classes for handling geometric objects, for calculating Phong and Cook-Torrance
light calculations, and for tracing rays and determining the intersections of rays with
geometric objects. There is no nice user interface; instead, you have to write C++
code to interact with the RayTracing class library. Geometric modeling is done by
making C++ function calls to create objects and set their properties. There is
source code for high level control of ray tracing, but you may need to modify this to fit
your application.
Geometric objects supported: (Members of the ViewableObject
class): Triangles, Parallelograms, Parallelepipeds (includes cubes and rectangular prisms),
Cylinders, Cones, Spheres, Ellipsoids, Toruses, and collections of Bezier patches.
Texture mapping features: Some support for checkerboard
patterns, for texture maps from bitmap files, for bump mapping, and for combining multiple
texture maps. Also some fairly general methods for working with texture coordinates.
Lighting models: Phong and Cook-Torrance. The
Phong lighting model includes all the standard OpenGL material and light properties.
Camera: Orthographic and perspective views
supported.
OpenGL/GLUT previewing: The scene can be viewed
with OpenGL/GLUT before ray tracing is begun. A convenience for placing
objects correctly and choosing the view. This is new for release 2.0.
Objects's extents: Low-level routines calculate
bounding planes for objects. Available for future use in spatial data
structures such as BSP trees or k-d-trees or octtrees. This is new
in release 2.0.
Changes from Release 1.0 to Release 2.0: Release 1.0 was the version described in Appendix B of my book mentioned above. Release 2.0 adds a couple new features including (a) the OpenGL/GLUT previewing and (b) the low level routines for calculating the extents of objects. More information about the changes between release 1.0 and 2.0 is available.
The software is distributed with two main programs that were designed mostly for testing purposes, RayTrace and RayTrace2. These generate the following images:
![]() |
The main program RayTrace generates this image. In the background, there are two triangles with checkerboard texture maps. In the center is a largely grayish transparent sphere. Above the other objects, there is a small blue sphere, and there are several small yellow triangles floating in the air. A larger version of the image is also available. The larger version took approximately 9 seconds to generate (on a 350 MHz Pentium 3). |
![]() |
The main program RayTrace2 generates
the rather full second image. There is a back wall (texture mapped with blue and
black stripes). The side walls are triangles and are reflective. Scattered
around the scene are various spheres, tori, cylinders, cones, parallelepipeds,
ellipsoids, and Bezier patches. In the back right corner, there is a curved mirror
mounted in the corner --- this is formed from Bezier patches. For a better look,
check out the larger version of the image. The larger
version took approximately 10.5 minutes to generate (again, on 350 MHz Pentium 3). There is also an annotated version of the large image available, if you are trying to figure out what all the different shapes are. |
Legalities: You may use this software without restriction. If you use it for substantial projects or commercial projects, please let me know (recognition of this type is one of the ways us academic types get rewarded.). In particular, its use should be acknowledged in any publication and in any product. In addition, if you find or fix bugs, please let me know, so that I can update the software for everyone else. The software is distributed "as-is", and carries no warranty of any kind.
Software available. Release 2.0. There are two ways to get the software:
Documentation: See appendix B of the above-mentioned book. Or examine the source code.... (Sorry, that's what is available for now.)
Running the software: Start with the project RayTrace as the main program. If you make the window larger, it takes proportionally longer for the image to draw. It is highly recommended that you use an optimizing compiler such as Visual C++'s Release mode when not debugging your code --- this will improve runtimes substantially.. When debugging your code, keep the window very small to get decent run times.